<?php
/**
 * Template Name: Undersida med meny
 * Description: En sida med en undermeny till vänster.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

get_header(); ?>

<h1><?php echo $post->title; ?></h1>
<div id="content_plate" class="clearfix">
    <div id="content_left">
<?php
    $has_subpages = false;
    // Check to see if the current page has any subpages
    $children = wp_list_pages('&child_of='.$post->ID.'&echo=0');
    if($children) {
        $has_subpages = true;
    }
    // Reseting $children
    $children = "";

    // Fetching the right thing depending on if we're on a subpage or on a parent page (that has subpages)
    if(is_page() && $post->post_parent) {
        // This is a subpage
        $children = wp_list_pages("title_li=&child_of=".$post->post_parent ."&echo=0");
    } else if($has_subpages) {
        // This is a parent page that have subpages
        $children = wp_list_pages("title_li=&child_of=".$post->ID ."&echo=0");
    }

    // Check to see if we have anything to output
    if ($children) {
?>
        <ul class="sub_menu">
            <?php echo $children; ?>
        </ul>
<?php
    }
?>
        <div id="content_calendar">
<?php
            print_agenda($post->slug, 10);
?>
        </div>
    </div>

    <div id="content_right">
        Innehåll
    </div>
</div>
<?php get_footer(); ?>